package com.ruoyi.system.mqtt;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.apiResult.Result;
import com.ruoyi.common.cache.CacheComponent;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.apiQuery.MqttQuery;
import com.ruoyi.system.domain.ZsyyParkTicket;
import com.ruoyi.system.domain.ZsyyParkTicketType;
import com.ruoyi.system.mapper.ZsyyParkTicketMapper;
import com.ruoyi.system.mapper.ZsyyParkTicketTypeMapper;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Component
public class MqttService {
	public static String MQTT_CLIENTID = "CB_987654321";

	public static String MQTT_SERVER = "test.tdzntech.com";
//    public static String MQTT_SERVER = "47.104.141.149";

	public static String MQTT_PORT = "1883";
	public static String USERNAME = "test";
	public static String PASSWORD = "test";

	@Autowired
	private ZsyyParkTicketTypeMapper ticketTypeMapper ;
	@Autowired
	private ZsyyParkTicketMapper ticketMapper ;

	@Autowired
	private CacheComponent cacheComponent;  //Redis

	//通过uuid获取Redis存入的数据
	private Result  getRedisDataByMqtt(String uuid) throws InterruptedException {
		Result result = new Result();
		String data = null;
		for (int i = 0; i < 5; i++) {
			Thread.sleep(300);
			data = cacheComponent.getRaw(uuid);
			if (!CommonUtil.isEmpty(data)){
				break;
			}
		}
		if (CommonUtil.isEmpty(data)){
			result.setData("数据为空");
			result.setCode(Result.Code.FAILED);
		}else {
			JSONObject jsonObj = JSONObject.parseObject(data);
			result.setData(jsonObj);
		}
		return result;
	}
	//通过uuid获取Redis存入的数据
	private MqttQuery getRedisDataByMqttQuery(String uuid) throws InterruptedException {
		String data = null;
		for (int i = 0; i < 10; i++) {
			Thread.sleep(300);
			data = cacheComponent.getRaw(uuid);
			if (!CommonUtil.isEmpty(data)){
				break;
			}
		}
		if (CommonUtil.isEmpty(data)){
			MqttQuery re = new MqttQuery();
			re.setCode(2);
			re.setMsg("未接收到返回数据");
			return re;
		}else {
			MqttQuery jsonObj = JSON.parseObject(data,MqttQuery.class);
			return jsonObj;
		}

	}

	//    @GetMapping("/openMqtt")
//    @ApiOperation(value = "连接mqtt服务")
	public void openMqtt(String parkCode) {
//        MqttParkClient.PARK_SUB_TOPIC = "tpc/"+parkCode;
		MqttParkClient.CreateMqttConnection(MQTT_SERVER, MQTT_PORT,MQTT_CLIENTID,USERNAME, PASSWORD);
	}

	@GetMapping("/getChannels")
	@ApiOperation(value = "通道001-获取通道列表")
	public Result getChannels( @ApiParam(value = "停车场编码",required = true)String parkCode) {
		Result result = new Result();
		try {
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map map = new HashMap();
			map.put("parkCode",parkCode);
			map.put("action","all");
			map.put("code",1);
			map.put("opt","admin");
			map.put("msg","");
			map.put("dataItems",list);
			map.put("serviceId","manage.channels");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+parkCode);    //发送数据是tcp
			result = getRedisDataByMqtt(uuid.toString());

		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}



	/**
	 * action参数：抬闸：opengate，落闸：closegate
	 * 通道id
	 * 停车场编码
	 * @Param [action, channelId, parkCode]
	 * @return com.ruoyi.common.apiResult.Result
	 **/
	@GetMapping("/openOrclosegate")
	@ApiOperation(value = "通道002-指定通道抬闸/落闸")
	public Result openOrclosegate(String action,Integer channelId,String parkCode) {
		Result result = new Result();
		try {
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("channelId",channelId);    //通道编号
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode",parkCode);
			map.put("code",1);
			map.put("opt","admin");
			map.put("msg","");
			map.put("action",action);
			map.put("dataItems",list);
			map.put("serviceId","manage.channels");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+parkCode);    //发送数据是tcp
			result = getRedisDataByMqtt(uuid.toString());

		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}



	/**
	 * @Author wangghua
	 * @Description
	 * @Date 18:27 2021/7/29
	 * @Param [page页码, pageSize每页显示条数, name车位组名称, parkCode停车场编码]
	 * @return com.ruoyi.common.apiResult.Result
	 **/
	@GetMapping("/allManageCargroups")
	@ApiOperation(value = "车位组001-分页查询车位组（对应月票类型）")
	public Result allManageCargroups( Integer page,
									  Integer pageSize,
									  String name,
									  String parkCode) {
		Result result = new Result();
		try {
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("page",page);    //页码
			m1.put("pageSize",pageSize);    //每页显示条数
			m1.put("name",name);    //车位组名称
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode",parkCode);
			map.put("action","query");
			map.put("code",1);
			map.put("msg","");
			map.put("dataItems",list);
			map.put("serviceId","manage.cargroups");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+parkCode);    //发送数据是tcp
			Thread.sleep(1000);
			result = getRedisDataByMqtt(uuid.toString());


		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}

	@GetMapping("/addManageCargroups")
	@ApiOperation(value = "车位组002-添加车位组（对应添加月票类型）")
	public Result addManageCargroups(@RequestBody MqttCarGroupVo mqttCarGroupVo) {
//        openMqtt(mqttCarGroupVo.getParkCode());
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(mqttCarGroupVo.getParkCode())){
				result.setMessage(Result.Code.FAILED,"停车场编码不能为空");
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("GroupName", mqttCarGroupVo.getGroupName());    //车位组名称
			m1.put("GroupTel", mqttCarGroupVo.getGroupTel());    //电话号码
			m1.put("GroupNum", mqttCarGroupVo.getGroupNum());    //车位个数
			m1.put("CreateTime", DateUtils.getStringToday());    //创建时间
			m1.put("Remark", mqttCarGroupVo.getRemark());    //备注
			m1.put("BeginTime", mqttCarGroupVo.getBeginTime());    //起始时间
			m1.put("EndTime", mqttCarGroupVo.getEndTime());    //结束时间
			m1.put("LeftNum", mqttCarGroupVo.getLeftNum());    //结束时间
			m1.put("IsFree", mqttCarGroupVo.getIsFree());    //是否免费车组:0：否，1：是
			m1.put("UnitFee", mqttCarGroupVo.getUnitFee());    //单价
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", mqttCarGroupVo.getParkCode());
			map.put("action","add");
			map.put("code",1);
			map.put("msg","");
			map.put("dataItems",list);
			map.put("serviceId","manage.cargroups");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ mqttCarGroupVo.getParkCode());    //发送数据是tcp
			result = getRedisDataByMqtt(uuid.toString());

		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}


	@GetMapping("/editManageCargroups")
	@ApiOperation(value = "车位组003-修改车位组（对应修改月票类型）")
	public Result editManageCargroups(@RequestBody MqttCarGroupVo mqttCarGroupVo) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(mqttCarGroupVo.getUUID())){
				result.setMessage(Result.Code.FAILED,"UUID唯一标识不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(mqttCarGroupVo.getParkCode())){
				result.setMessage(Result.Code.FAILED,"停车场编码不能为空");
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("ID", mqttCarGroupVo.getID());    //车位组名称
			m1.put("GroupName", mqttCarGroupVo.getGroupName());    //车位组名称
			m1.put("GroupTel", mqttCarGroupVo.getGroupTel());    //电话号码
			m1.put("GroupNum", mqttCarGroupVo.getGroupNum());    //车位个数
			m1.put("CreateTime", DateUtils.getStringToday());    //创建时间
			m1.put("Remark", mqttCarGroupVo.getRemark());    //备注
			m1.put("BeginTime", mqttCarGroupVo.getBeginTime());    //起始时间
			m1.put("EndTime", mqttCarGroupVo.getEndTime());    //结束时间
			m1.put("LeftNum", mqttCarGroupVo.getLeftNum());    //结束时间
			m1.put("IsFree", mqttCarGroupVo.getIsFree());    //是否免费车组:0：否，1：是
			m1.put("UnitFee", mqttCarGroupVo.getUnitFee());    //单价
			m1.put("UUID", mqttCarGroupVo.getUUID());    //唯一标识
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", mqttCarGroupVo.getParkCode());
			map.put("action","edit");
			map.put("code",1);
			map.put("msg","");
			map.put("dataItems",list);
			map.put("serviceId","manage.cargroups");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ mqttCarGroupVo.getParkCode());    //发送数据是tcp

			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			ZsyyParkTicketType ticketType = ticketTypeMapper.getByUuid(mqttCarGroupVo.getUUID());
			ticketType.setTicketName(mqttCarGroupVo.getGroupName());  //车位组名称
			ticketType.setPrice(new BigDecimal(mqttCarGroupVo.getUnitFee()));    //单价
			ticketType.setStartTime(format.parse(mqttCarGroupVo.getBeginTime()));   //起始时间
			ticketType.setEndTime(format.parse(mqttCarGroupVo.getEndTime()));//结束时间
			ticketTypeMapper.updateById(ticketType);
			result = getRedisDataByMqtt(uuid.toString());

		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}
	@GetMapping("/deleteManageCargroups")
	@ApiOperation(value = "车位组004-删除车位组（对应删除月票类型）")
	public Result deleteManageCargroups(@RequestBody MqttCarGroupVo mqttCarGroupVo) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(mqttCarGroupVo.getUUID())){
				result.setMessage(Result.Code.FAILED,"唯一标识不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(mqttCarGroupVo.getParkCode())){
				result.setMessage(Result.Code.FAILED,"停车场编码不能为空");
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("ID", mqttCarGroupVo.getID());    //车位组名称
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", mqttCarGroupVo.getParkCode());
			map.put("action","delete");
			map.put("code",1);
			map.put("msg","");
			map.put("dataItems",list);
			map.put("serviceId","manage.cargroups");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ mqttCarGroupVo.getParkCode());    //发送数据是tcp
			ticketTypeMapper.deleteByUuid(mqttCarGroupVo.getUUID());   //唯一标识
			result = getRedisDataByMqtt(uuid.toString());

		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}

	@GetMapping("/queryManageCars")
	@ApiOperation(value = "车辆001-分页查询所有车辆")
	public Result queryManageCars(@ApiParam(value = "页码",required = true)Integer page,
								  @ApiParam(value = "每页显示条数",required = true)Integer pageSize,
								  @ApiParam(value = "车牌号",required = false)String carNum,
								  @ApiParam(value = "车主姓名",required = false)String owner,
								  @ApiParam(value = "停车场编码",required = true)String parkCode) {
		Result result = new Result();
		try {
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("page",page);    //页码
			m1.put("pageSize",pageSize);    //每页显示条数
			m1.put("carNum",carNum);    //车牌号
			m1.put("owner",owner);    //车主名称
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode",parkCode);
			map.put("code",1);
			map.put("opt","admin");
			map.put("msg","");
			map.put("action","query");
			map.put("dataItems",list);
			map.put("serviceId","manage.cars");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+parkCode);
			result = getRedisDataByMqtt(uuid.toString());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}

	@GetMapping("/addManageCars")
	@ApiOperation(value = "车辆002-添加车辆")
	public Result addManageCars(@RequestBody MqttCarVo mqttCarVo) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(mqttCarVo.getParkCode())){
				result.setMessage(Result.Code.FAILED,"停车场编码不能为空");
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("CarNum", mqttCarVo.getCarNum());    //车牌号
			m1.put("Owner", mqttCarVo.getOwner());    //车主名称
			m1.put("CarTypeCode", mqttCarVo.getCarTypeCode());    //车辆类型编码
			m1.put("CarGroupID", mqttCarVo.getCarGroupID());    //车组ID
			m1.put("CarGroup", mqttCarVo.getCarGroup());    //车组名称
			m1.put("Balance", mqttCarVo.getBalance());    //余额
			m1.put("CarMMoney", mqttCarVo.getCarMMoney());    //月费标准
			m1.put("TimeStart", mqttCarVo.getTimeStart());    //有效开始时间
			m1.put("TimeEnd", mqttCarVo.getTimeEnd());    //有效结束时间
			m1.put("Tel", mqttCarVo.getTel());    //车主电话
			m1.put("CarSpaceNum", mqttCarVo.getCarSpaceNum());    //车位号
			m1.put("State", mqttCarVo.getState());    //启用状态
			m1.put("Remark", mqttCarVo.getRemark());    //备注
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", mqttCarVo.getParkCode());
			map.put("code",1);
			map.put("opt","admin");
			map.put("msg","");
			map.put("action","add");
			map.put("dataItems",list);
			map.put("serviceId","manage.cars");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ mqttCarVo.getParkCode());
			result = getRedisDataByMqtt(uuid.toString());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}


	@GetMapping("/editManageCars")
	@ApiOperation(value = "车辆003-修改车辆")
	public Result editManageCars(@RequestBody MqttCarVo mqttCarVo) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(mqttCarVo.getUUID()) || CommonUtil.isEmpty(mqttCarVo.getID())){
				result.setMessage(Result.Code.FAILED,"唯一标识或ID不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(mqttCarVo.getParkCode())){
				result.setMessage(Result.Code.FAILED,"停车场编码不能为空");
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("ID", mqttCarVo.getID());    //车辆ID
			m1.put("CarNum", mqttCarVo.getCarNum());    //车牌号
			m1.put("Owner", mqttCarVo.getOwner());    //车主名称
			m1.put("CarTypeCode", mqttCarVo.getCarTypeCode());    //车辆类型编码
			m1.put("CarGroupID", mqttCarVo.getCarGroupID());    //车组ID
			m1.put("CarGroup", mqttCarVo.getCarGroup());    //车组名称
			m1.put("Balance", mqttCarVo.getBalance());    //余额
			m1.put("CarMMoney", mqttCarVo.getCarMMoney());    //月费标准
			m1.put("TimeStart", mqttCarVo.getTimeStart());    //有效开始时间
			m1.put("TimeEnd", mqttCarVo.getTimeEnd());    //有效结束时间
			m1.put("Tel", mqttCarVo.getTel());    //车主电话
			m1.put("CarSpaceNum", mqttCarVo.getCarSpaceNum());    //车位号
			m1.put("State", mqttCarVo.getState());    //启用状态
			m1.put("Remark", mqttCarVo.getRemark());    //备注
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", mqttCarVo.getParkCode());
			map.put("code",1);
			map.put("opt","admin");
			map.put("msg","");
			map.put("action","edit");
			map.put("dataItems",list);
			map.put("serviceId","manage.cars");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ mqttCarVo.getParkCode());

			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			ZsyyParkTicket ticket = ticketMapper.getByMqttUUID(mqttCarVo.getUUID(), mqttCarVo.getID());
			ticket.setMonthTicketConfigId(mqttCarVo.getCarGroupID().longValue());  //月票类型ID/车位组ID
			ticket.setOriginPrice(new BigDecimal(mqttCarVo.getCarMMoney()));    //票原价
			ticket.setFavorPrice(new BigDecimal(mqttCarVo.getCarMMoney()));    //票折后价
			ticket.setStartTime(format.parse(mqttCarVo.getTimeStart()));   //起始时间
			ticket.setEndTime(format.parse(mqttCarVo.getTimeEnd()));//结束时间
			ticket.setCarNo(mqttCarVo.getCarNum());    //车牌号
			ticket.setUserName(mqttCarVo.getOwner());    //车主姓名
			ticket.setUserPhone(mqttCarVo.getTel());    //车主电话
			ticketMapper.updateById(ticket);
			result = getRedisDataByMqtt(uuid.toString());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}


	@GetMapping("/deleteManageCars")
	@ApiOperation(value = "车辆004-删除车辆")
	public Result deleteManageCars(@RequestBody MqttCarVo mqttCarVo) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(mqttCarVo.getUUID()) || CommonUtil.isEmpty(mqttCarVo.getID())){
				result.setMessage(Result.Code.FAILED,"唯一标识或ID不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(mqttCarVo.getParkCode())){
				result.setMessage("停车场编码不能为空");
				result.setCode(Result.Code.FAILED);
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("ID", mqttCarVo.getID());    //车辆ID
			m1.put("UUID", mqttCarVo.getUUID());    //唯一标识
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", mqttCarVo.getParkCode());
			map.put("code",1);
			map.put("opt","admin");
			map.put("msg","");
			map.put("action","delete");
			map.put("dataItems",list);
			map.put("serviceId","manage.cars");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ mqttCarVo.getParkCode());
			//删除本地数据库数据
			ticketMapper.deleteByMqttUUID(mqttCarVo.getUUID(), mqttCarVo.getID());

			result = getRedisDataByMqtt(uuid.toString());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}

	@PostMapping("/payQqueryfeebyplate")
	@ApiOperation(value = "查询车辆缴费金额")
	public Result payQqueryfeebyplate(@RequestBody MqttQueryFeeVo mqttQueryFeeVo) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(mqttQueryFeeVo.getPayScene()) || CommonUtil.isEmpty(mqttQueryFeeVo.getParkCode())){
				result.setMessage(Result.Code.FAILED,"支付场景或停车场编码不能为空");
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("plateNumber", mqttQueryFeeVo.getPlateNumber());    //车牌号
			m1.put("payScene", mqttQueryFeeVo.getPayScene());    //支付场景：0：场内预付，1：结算待支付(直付)，2：无牌车请求结算，默认0
			m1.put("outChannelid", mqttQueryFeeVo.getOutChannelid());    //出口通道标志，pay_scene为1,2时必传
			m1.put("recordNo", mqttQueryFeeVo.getRecordNo());    //入场流水号，pay_scene为0,2时必传 ，没有收到上报记录可下发recordNo 为空串
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", mqttQueryFeeVo.getParkCode());
			map.put("code",1);
			map.put("dataItems",list);
			map.put("serviceId","pay.queryfeebyplate");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ mqttQueryFeeVo.getParkCode());
			result = getRedisDataByMqtt(uuid.toString());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}

	//公共查询接口
	public MqttQuery commonMqtt( MqttQuery mqttQuery) {
		MqttQuery result = null;
		try {
			if("2KST6MLE".equals(mqttQuery.getParkCode())){
				mqttQuery.setParkCode("TDZN/100760P5757");
			}
			String uuid = UUID.randomUUID().toString();
			mqttQuery.setUuid(uuid);
			MqttParkClient.publish(JSON.toJSONString(mqttQuery),  "tcp/"+ mqttQuery.getParkCode());
			result = getRedisDataByMqttQuery(uuid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}



	/*
	 * @Author wangghua
	 * @Description 无牌车入场请求下发成功后，车辆入场会上报入场记录，且上报的车牌为：无+下发的车牌 示例入场车牌：无贵A16V2A
	 * @Date 11:19 2021/4/6
	 * @Param [plateNumber, channelid, parkCode]
	 * @return com.admin.util.Result
	 **/

	@GetMapping("/recordInNocarnum")
	@ApiOperation(value = "3.9 无牌车入场请求")
	public Result recordInNocarnum(@RequestParam @ApiParam(value = "车牌号",required = true)String plateNumber,
								   @RequestParam @ApiParam(value = "通道ID",required = true)String channelid,
								   @RequestParam @ApiParam(value = "停车场编码",required = true)String parkCode) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(plateNumber)){
				result.setMessage(Result.Code.FAILED,"车牌号不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(channelid)){
				result.setMessage(Result.Code.FAILED,"通道编号不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(parkCode)){
				result.setMessage("停车场编码不能为空");
				result.setCode(Result.Code.FAILED);
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("channelId", channelid);    //通道ID
			m1.put("plateNumber", "无"+plateNumber);    //车牌号，7位由数字和大写字母组合的车牌
			m1.put("requestTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));    //请求时间
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", parkCode);
			map.put("code",1);
			map.put("dataItems",list);
			map.put("serviceId","record.in.nocarnum");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ parkCode);
			result = getRedisDataByMqtt(uuid.toString());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}

	@PostMapping("/controlInAndOut")
	@ApiOperation(value = "3.13 平台控制进出场")
	public Result controlInAndOut(@RequestBody ControlInAndOutVo controlInAndOutVo) {
		Result result = new Result();
		try {
			if (CommonUtil.isEmpty(controlInAndOutVo.getPlateId())){
				result.setMessage(Result.Code.FAILED,"流水唯一标识不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(controlInAndOutVo.getChannelid())){
				result.setMessage(Result.Code.FAILED,"通道编号不能为空");
				return result;
			}
			if (CommonUtil.isEmpty(controlInAndOutVo.getParkCode())){
				result.setMessage("停车场编码不能为空");
				result.setCode(Result.Code.FAILED);
				return result;
			}
			UUID uuid = UUID.randomUUID();
			List list = new ArrayList();
			Map m1 = new HashMap();
			m1.put("channelId", controlInAndOutVo.getChannelid());    //通道ID
			m1.put("cmd", controlInAndOutVo.getCmd());    //命令
			m1.put("type", controlInAndOutVo.getType());    //操作（对应入场和出场）
			m1.put("plateId", controlInAndOutVo.getPlateId());    //流水唯一标识
			m1.put("operator", controlInAndOutVo.getOperator());    //抬闸管理员
			m1.put("openGateCase", controlInAndOutVo.getOpenGateCase());    //放行原因
			list.add(m1);
			Map map = new HashMap();
			map.put("parkCode", controlInAndOutVo.getParkCode());
			map.put("code",1);
			map.put("msg","");
			map.put("dataItems",list);
			map.put("serviceId","parking.remote");
			map.put("uuid",uuid);
			MqttParkClient.publish(JSON.toJSONString(map),  "tcp/"+ controlInAndOutVo.getParkCode());
			result = getRedisDataByMqtt(uuid.toString());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(Result.Code.SYSTEMERROR);
		}
		return result;
	}


}
